﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class TankHp : MonoBehaviour
{
    public int hp = 100;            //坦克血量
    public GameObject tankExp;     //坦克爆炸
    public AudioClip tankExpAud;   //坦克爆炸音效
    public Slider hpslider;        //血条
    public Text gameOverText;      //游戏结束文本
    private int hpsum;             //总血量
    // Start is called before the first frame update
    void Start()
    {
        hpsum = hp;
        gameOverText = GameObject.Find("GameOverText").GetComponent<Text>();
        gameOverText.enabled = false;
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    private void TankDamage()
    {
        if(hp>0){
            hp = hp - Random.Range(10, 15);
            hpslider.value = (float)hp / hpsum;
            if(hp<=0){
                AudioSource.PlayClipAtPoint(tankExpAud, transform.position);
                GameObject.Instantiate(tankExp, transform.position + Vector3.up, transform.rotation);
                GameObject.Destroy(this.gameObject);
                gameOverText.enabled = true;
                Time.timeScale = 0.0f;
            }
        }
    }
}
